package kr.hkit.androidcomplete02.br;

import kr.hkit.androidcomplete02.R;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class NapAlarm extends Activity {

	static final int NAPNOTI = 1;
	NotificationManager mNotiManager;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.noti_napalarm);
		mNotiManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
	}
	
	public void mOnClick(View v) {
		Toast.makeText(NapAlarm.this, "안녕히 주무세요", Toast.LENGTH_LONG).show();
		
		v.postDelayed(new Runnable() {
			
			@Override
			public void run() {
				Intent intent = new Intent(NapAlarm.this, NapEnd.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);	
				PendingIntent content = PendingIntent.getActivity(NapAlarm.this, 0, intent, 0);
				
				Notification noti = new Notification.Builder(NapAlarm.this)
				.setTicker("일어나세요")
				.setContentTitle("기상 시간")
				.setContentText("일어나! 일할 시간이야.")
				.setSubText("일을 해야 돈을 벌고 돈을 벌어야 밥먹고 살지!!")
				.setSmallIcon(R.drawable.coin100)
				.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.dog))
				.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
				.setVibrate(new long[] {1000,1000,500,500,200,200,200,200,200,200})
				.setLights(0xff00ff00, 500, 500)
				.setContentIntent(content)
				.build();
			
				noti.flags |= (Notification.FLAG_INSISTENT | Notification.FLAG_SHOW_LIGHTS); //?
				
				mNotiManager.notify(NapAlarm.NAPNOTI, noti); // ??
			}
		}, 5*1000);
	}
}
